package org.ddxz.demo.mock.service.impl;


import cn.hutool.core.map.MapBuilder;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.ddxz.demo.mock.service.BaoQingSisService;
import org.springframework.stereotype.Service;

/**
 * desc
 *
 * @author zhuzonggang
 * @date 2025/9/7 21:53
 */

@Service
public class BaoQingSisServiceImpl implements BaoQingSisService {
    @Override
    public Object login(JSONObject body) {
        return MapBuilder.create()
                .put("code", 200)
                .put("msg", "success")
                .put("token", "21f06193df41ca46962c57c1d800fa0b4494b14541eb15e47918ddf44e2a6a79")
                .build();
    }

    @Override
    public Object realTime(JSONObject body) {
        JSONObject rst = new JSONObject();
        rst.put("code", 200);
        rst.put("msg", "success");
        rst.put("data", new JSONArray());
        if (body.containsKey("ns")) {
            for (String str : body.getJSONArray("ns").toArray(new String[]{})) {
                Double val;
                switch (str) {
                    case "fdl1":
                        val = 29382.27;
                        break;
                    case "fdl2":
                        val = 16919.109;
                        break;
                    case "cydl1":
                    case "cydl2":
                        val = 0.0609;
                        break;
                    case "gdmh1":
                    case "gdmh2":
                        val = 302.6;
                        break;
                    default:
                        val = Math.random();
                        break;
                }
                rst.getJSONArray("data")
                        .add(MapBuilder.create()
                                .put("n", str)
                                .put("s", 1)
                                .put("t", System.currentTimeMillis())
                                .put("v", val)
                                .build());
            }
        }

        return rst;
    }
}
